package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.course.CustomerPageDTO;
import com.qk.dto.customer.CustomerInsertDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 上官徵羽
 * @version 1.0
 * @since 2025-10-19 21:46
 */
@Slf4j
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    @GetMapping
    public Result listPage(CustomerPageDTO customerPageDTO){
        return Result.success(customerService.listPage(customerPageDTO));
    }

    @PostMapping
    public Result insertCustomer(@RequestBody CustomerInsertDTO customerInsertDTO){
        customerService.insertCustomer(customerInsertDTO);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable("id") Integer id){
        return Result.success(customerService.getCustomerById(id));
    }

    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return Result.success();
    }
}
